<template>
	<view class="goods-detail">
		<image :src="share_path"  class="share-img" v-if="share_path!=''"></image>
		<u-popup
		:show="showShare" 
		@close="showShare=false" 
		mode="bottom" 
		:overlayOpacity="0.6">
			<view class="share-container">
				<view class="item" @click="share(1)">
					<image src="https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/index/fxpyq.png" class="fx-img" mode="widthFix"></image>
					<view class="title">分享朋友圈</view>
				</view>
				<view class="item" @click="share(2)">
					<image src="https://farm-city.oss-cn-hangzhou.aliyuncs.com/static/index/fxwxq.png" class="fx-img" mode="widthFix"></image>
					<view class="title">分享微信</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				showShare: false,
				share_path: '',
				type:1,
				id: 0
			}
		},
		onNavigationBarButtonTap(e) {
			_this.showShare=true
		},
		onLoad(e) {
			_this=this
			this.option_id = e.id
			if(this.option_id==undefined){
				uni.$u.toast("提交参数有误")
				setTimeout(()=>{
					uni.navigateBack({})
				},2000)
			}
			if(e.type){
				_this.type=e.type
			}
			_this.id=e.id
			this.getgoods()
		},
		methods: {
			share(type){
				if(type==1){
					//分享到朋友圈
					uni.share({
						provider: "weixin",
						scene: "WXSceneTimeline",
						type: 2,
						imageUrl: _this.share_path,
						success(res) {
							console.log("success:" + JSON.stringify(res));
							_this.$u.toast('分享成功')
							_this.sign(3)
						},
						fail(err) {
							console.log("fail:" + JSON.stringify(err));
						}
					});
				}else{
					//分享到聊天界面
					uni.share({
						provider: "weixin",
						scene: "WXSceneSession",
						type: 2,
						imageUrl: _this.share_path,
						success(res) {
							console.log("success:" + JSON.stringify(res));
							_this.$u.toast('分享成功')
							_this.sign(4)
						},
						fail(err) {
							console.log("fail:" + JSON.stringify(err));
						}
					});
				}
			},
			async sign(type){
				let params={
					type
				}
				const data = await _this.$post('api/user_qd',params)
				if (data.code == 200) {
				} else {
				}
			},
			//获取商品信息
			async getgoods() {
				const params = {
					id: _this.id,
					type: _this.type,
				}
				const data = await _this.$post('api/goods_fx',params)
				if(data.code==200){
					_this.share_path=data.data.share_path
				}else{
					uni.$u.toast(data.msg)
					setTimeout(()=>{
						uni.navigateBack({})
					},2000)
				}
			},
		}
	}
</script>
<style lang="scss" scoped>
	@import "@/static/css/goods.scss";
	.goods-detail{
		height: 100%;
		overflow: hidden;
		.share-img{
			width: 100%;
			height: 100%;
		}
	}
</style>
